package com.zhouchb.stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/31 :22:21
 * @Description
 */
public class FileInputOutputStreamTest {
    public static void main(String[] args) {
        FileInputStream fi = null;
        FileOutputStream fw = null;
        try {
            File file = new File("IO/small.png");
            File filew = new File("IO/small2.png");
            fi = new FileInputStream(file);
            fw = new FileOutputStream(filew);
            byte[] buffer = new byte[5];
            int len;
            while ((len=fi.read(buffer))!=-1){
                fw.write(buffer,0,len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fi!=null)
                fi.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fw!=null)
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
